/*
	addsub8.v
	Full function adder/subtractor using Kogge-Stone adder
	
	This project and file(s) are released under GNU GPL v3.
	Please find license file from root directory.
	Meng Sun (c) 2013 <leon.meng.sun@gmail.com>
*/

module addsub8 (A, B, CBi, M, Y, CBo, OV);

input [7:0] A, B;
input CBi, M;
output [7:0] Y;
output CBo, OV;

wire [7:0] A, B;
wire CBi, M;
wire [7:0] Y;
reg CBo, OV;

reg modeCBi;
reg [7:0] modeB;
wire bareCBo;

always @ (A or B or CBi or M)
begin
	modeCBi = CBi ^ M;
	modeB = B ^ {8{M}};
end

always @ (Y or bareCBo or M or modeB or A)
begin
	CBo = bareCBo ^ M;
	OV = (A[7] & modeB[7] & ~Y[7]) | (~A[7] & ~modeB[7] & Y[7]);
end

kstoneadder bareAdder (A, modeB, modeCBi, Y, bareCBo);

endmodule